#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Math/Interpolations/Extrapolator.h>
#pragma unmanaged 
#include <ql\math\interpolations\interpolation2d.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#define STRUCT
namespace Cephei { namespace QL { namespace Math { namespace Interpolations {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IInterpolation2D
	public ref class CInterpolation2D : 
            public CExtrapolator,
            public Cephei::QL::Math::Interpolations::IInterpolation2D
	{
	protected: 
		boost::shared_ptr<QuantLib::Interpolation2D>* _ppInterpolation2D;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::Interpolation2D>* _phInterpolation2D;
#endif
		Object^ _Interpolation2DOwner;     // reference to object that manages the storage for this object
	internal:
		CInterpolation2D ();
        CInterpolation2D (boost::shared_ptr<QuantLib::Interpolation2D>& childNative, Object^ owner);
        CInterpolation2D (QuantLib::Interpolation2D& childNative, Object^ owner);
        CInterpolation2D (CInterpolation2D^ copy);
        CInterpolation2D (System::Type^ t);
#ifdef STRUCT
        CInterpolation2D (QuantLib::Interpolation2D childNative);
#endif       
#ifdef HANDLE
		CInterpolation2D (QuantLib::Handle<QuantLib::Interpolation2D>& childNative, Object^ owner);
		CInterpolation2D (QuantLib::Handle<QuantLib::Interpolation2D> childNative);
#endif
		virtual ~CInterpolation2D ();
		!CInterpolation2D ();

	internal:
		QuantLib::Interpolation2D& GetReference ();
		boost::shared_ptr<QuantLib::Interpolation2D>& GetShared ();
		QuantLib::Interpolation2D* GetPointer ();
        void SetInterpolation2D (boost::shared_ptr<QuantLib::Interpolation2D> native)
        {
            if (_ppInterpolation2D != NULL)
                delete _ppInterpolation2D;
            _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (native);
            SetExtrapolator (boost::dynamic_pointer_cast<QuantLib::Extrapolator> (*_ppInterpolation2D));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::Interpolation2D>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Boolean IsInRange (Double x, Double y) ;
		virtual UInt64 LocateX (Double x) ;
		virtual UInt64 LocateY (Double y) ;
        property Cephei::QL::Math::Interpolations::IInterpolation2D^ Update 
        {
		    virtual Cephei::QL::Math::Interpolations::IInterpolation2D^ get () ;
        }
        property Double XMax 
        {
		    virtual Double get () ;
        }
        property Double XMin 
        {
		    virtual Double get () ;
        }
        property Cephei::IVector<Double>^ XValues 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Double YMax 
        {
		    virtual Double get () ;
        }
        property Double YMin 
        {
		    virtual Double get () ;
        }
        property Cephei::IVector<Double>^ YValues 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Cephei::QL::Math::IMatrix^ ZData 
        {
		    virtual Cephei::QL::Math::IMatrix^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CInterpolation2D_Factory : public System::MarshalByRefObject,  public IInterpolation2D_Factory
	{
	public:
        virtual IInterpolation2D^ Create ();
    };
   
/*Cephei*/ } /*QL*/ } /*Math*/ } /*Interpolations */}
